<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        // es2015之前的写法
        function containsAll(haystack) {
            var allNeedle = [];
            for (var j = 1, len = arguments.length; j < len; j++) {
                allNeedle.push(arguments[j]);
            }
            console.log(allNeedle);
            for (var i = 1, length = arguments.length; i < length; i++) {
                var needle = arguments[i];
                if (haystack.indexOf(needle) === -1) {
                    console.log(haystack + "不包含" + allNeedle);
                    return false;
                }
            }
            console.log(haystack + "包含" + allNeedle);
            return true;
        }
        containsAll("banana", "a", "v"); // banana不包含a,v
        containsAll("apple", "a", "p"); // apple包含a,p

        /*es2015新增的不确定参数机制
        不确定参数操作符（...）：rest操作符
        不确定参数是一个数组
        只能将最后一个参数定义为不确定参数
        传值时未传入不确定参数，则不确定参数为一个空数组*/
        function newContainsAll(haystack, ...needles) {
            for (var needle of needles) {
                if (haystack.indexOf(needle) === -1) {
                    console.log(haystack + "不包含" + needles);
                    return;
                }
            }
            console.log(haystack + "包含" + needles);
            console.log(needles instanceof Array); // true
        }
        newContainsAll("banana", "a", "v");
        newContainsAll("apple", "a", "p");
    </script>
</body>
</html>